<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

die('disabled');

$THEME->addBreadcrumb($this->adminUrl.'/run-test/', $this->lang('ap_title_run-test'));

set_time_limit(0);

$startTime = time();

$numPages = 2000;
$numPagesPerLevel = 20;
$numBlocks = 40;
$blockDepth = 3;
$parentid = 0;
$workspaceid = 1;

$blockContent = '<p>One of the fastest-developing technologies in computing is memory and data storage, which are driven by the
 constant need for increases in speed and storage size. Early computers used cards as memory before moving to chip technology.
Can you imagine working on a computer with only 1 KB of RAM? Many early computer programmers did. These pioneers realized very
rapidly that to work within the restraints of the technology, they would have to be diligent to avoid overloading their systems
 with frivolous commands.
</p><p>
As PHP developers, we live in a much more convenient world to code in than our colleagues who code in C++ or other stricter
languages. In our world, we do not have to concern ourselves with the handling of system memory because PHP handles that for
us. In the rest of the programming world, however, responsible coders use various functions to ensure that executed commands
 do not overwrite some other program data -- thus, crippling that running program.
</p>';
$blockHeading = 'The block heading';
$pageTitle = 'The Auto-generated page from hell!';
$pageContent = '<p>Memory management is usually handled by requests from the coder to allocate and release blocks of memory.
Allocated blocks can hold data of any type, and this process blocks off a certain amount of memory for
just that data and gives the program a method of addressing this data for when it needs to be accessed for
operations. The program is expected to release allocated memory when it has completed any operations, and
let the system and other programs use that memory. When a program does not release the memory back to the system, it is called a leak.
</p><p>
Leaks are a normal problem with any running program, and a certain amount is usually acceptable, especially when we know a running
program will terminate soon and release all of any memory allocated to it by default.
</p><p>
With programs you run and terminate arbitrarily, like almost all client applications, this is the case. Server applications
are expected to run indefinitely without termination or restart, making memory management absolutely vital to server daemon
programming. Even a small leak would eventually grow into a system-debilitating problem on a long-running program as memory
blocks are used and never released.
</p>';
$pageLevel = 0;


for($i=50; $i<(50+$numPages); $i++){
    if($pageLevel == $numPagesPerLevel){
        $pageLevel = 0;
        $parentid = $pageid;
    }
    // create our page
    $slug = 'slug'.rand();
    while($DB->countRows($CONFIG->dbprefix.'pages', "domain_id = 1 AND workspace_id = 1 AND slug = '{$slug}'")){
        $slug = 'slug'.rand();
    }
    $dbParams = array(
        'id' => $i,
        'parent_id' => $parentid,
        'slug' => $slug,
        'is_published' => 1,
        'workspace_id' => $workspaceid,
        'owner_id' => 1,
        'created_tstamp' => time(),
        'modified_tstamp' => time(),
        'is_default' => 0,
        'domain_id' => 1,
        'sorting' => $pageLevel
    );
    $pageid = $DB->insert($CONFIG->dbprefix.'pages', $dbParams);
    $pageLevel++;

    $LANG->updateContent('core', 'heading', $pageid, $pageTitle, '*', $workspaceid);
    $LANG->updateContent('content', 'page_menu', $pageid, $pageTitle, '*', $workspaceid);
    $LANG->updateContent('content', 'page_content', $pageid, $pageContent, '*', $workspaceid);

    $depth = 0;
    $parentBlockid = 'jfxpage-'.$pageid;
    for($i2 = 0; $i2 < $numBlocks; $i2++){
        if($depth == $blockDepth){
            $depth = 0;
            $parentBlockid = 'jfxpage-'.$pageid;
        }
        $dbParams = array(
            'id' => 'jfxpage-'.$pageid.'-content-'.$i2,
            'module_key' => 'content',
            'parent_id' => $parentBlockid,
            'page_id' => $pageid,
            'workspace_id' => $workspaceid,
            'sorting' => ($depth == 0) ? $i2 : $depth,
            'exec_order' => 0,
            'page_parent' => ($depth == 0) ? 1 : 0,
            'ajax_enabled' => 1,
            'class_name' => '',
            'is_droppable' => '1',
            'is_template' => 0,
            'block_style' => 'border: solid 1px red;'
        );
        $DB->insert($CONFIG->dbprefix.'blocks', $dbParams);
        $depth++;
        $parentBlockid = $dbParams['id'];

        $LANG->updateContent('core', 'heading', $dbParams['id'], $blockHeading, '*', $workspaceid);
        $LANG->updateContent('content', 'content', $dbParams['id'], $blockContent, '*', $workspaceid);
    }


}

$endTime = time();

echo 'Done '.$numPages.' pages and '.$numBlocks.' blocks on each in '.($endTime-$startTime).' seconds ('.(($endTime-$startTime)/60).' minutes)';















